package io.github.codelifeleno.jdbrelease.config;

import java.util.Objects;
import java.util.StringJoiner;

/**
 * 要连接数据库的配置
 */
public class DBConfig {

    private String driver;
    private String url;
    private String username;
    private String password;
    /**
     * 数据库域
     */
    private String schema;
    /**
     * 数据库类型，一般用于模式处理
     */
    private String type;

    @Override
    public String toString() {
        return new StringJoiner(", ", DBConfig.class.getSimpleName() + "[", "]")
                .add("driver='" + driver + "'")
                .add("url='" + url + "'")
                .add("username='" + username + "'")
                .add("password='" + password + "'")
                .add("schema='" + schema + "'")
                .add("type='" + type + "'")
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;

        DBConfig dbConfig = (DBConfig) o;
        return Objects.equals(getDriver(), dbConfig.getDriver()) && Objects.equals(getUrl(), dbConfig.getUrl()) && Objects.equals(getUsername(), dbConfig.getUsername()) && Objects.equals(getPassword(), dbConfig.getPassword()) && Objects.equals(getSchema(), dbConfig.getSchema()) && Objects.equals(getType(), dbConfig.getType());
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(getDriver());
        result = 31 * result + Objects.hashCode(getUrl());
        result = 31 * result + Objects.hashCode(getUsername());
        result = 31 * result + Objects.hashCode(getPassword());
        result = 31 * result + Objects.hashCode(getSchema());
        result = 31 * result + Objects.hashCode(getType());
        return result;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public DBConfig(String driver, String url, String username, String password, String schema, String type) {
        this.driver = driver;
        this.url = url;
        this.username = username;
        this.password = password;
        this.schema = schema;
        this.type = type;
    }

    /*
    *         <Driver>com.mysql.cj.jdbc.Driver</Driver>
        <!-- 数据库URL -->
        <Url>jdbc:mysql://localhost:3306/rwa_dev</Url>
        <!-- 用户名 -->
        <Username>rwa_dev</Username>
        <!-- 密码，可以使用系统环境变量 -->
        <Password>rwa_dev</Password>
        <!-- 域名 -->
        <Schema>rwa_dev</Schema>
        <!-- 数据库类型 -->
        <Type>MySQL</Type>*/
}
